import { Notifications } from '/imports/models/Notifications';

Template.home_notifications.onCreated(function() {
  this.infiniteScroll({
    query: {
      user_id: Meteor.userId()
    },
    publication: 'get.notifications',
    countPublication: 'get.notifications.counts'
  });
});

Template.home_notifications.onRendered(function() {
  $('[data-toggle="tooltip"]').tooltip({ trigger: "hover" });
});

Template.home_notifications.helpers({
  results: function() {
    return Notifications.find({
      user_id: Meteor.userId()
    }, {
      limit: Template.instance().getLimit(),
      sort: { createdAt: -1 }
    });
  },
  loading: function() {
    return !Template.instance().resultSub.ready();
  }
});

Template.home_notifications.events({
  'click .mark-all-read'(event) {
    event.preventDefault();
    Meteor.call('markAllRead');
  }
});